/*******************************************************
> Copyright (C) 2024 ==IOT== All rights reserved.
> File Name: string.cpp
> Author: IOT
> Website:www.slq.org
> Created Time: 2024年10月22日 星期二 16时14分05秒
***************************************************/

#include <iostream>
#include <cstring>

using namespace std;

class String {
	char *buf;
	int len;
	
	public:
		String() : buf(nullptr),len(0)
		{}
		String(const char *src)
		{
			len = strlen(src);
			buf = new char[len + 1]; // new 在分配空间时会自动赋0
			strcpy(buf, src);
		}
		~String()
		{
			if (buf != nullptr) {
				delete [] buf;
			}
		}
		
		bool operator==(const char *src)
		{
			return strcmp(this->buf, src) == 0 ? true : false;
		}
		bool operator==(String &str)
		{
			return strcmp(this->buf, str.buf) == 0 ? true : false;
		}
		
		bool operator>();
		bool operator<();
		bool operator!=();
		String operator+();
		String operator+=();
		
		find(char c); // 查找字符
		find(const char *src);
		find(String &str);
		
		String substr(int pos, int len); // 提取子串
		
		void show()
		{
			cout << buf << endl;
		}
};


int main(int argc,const char* argv[])
{
	String name("lucy");
	
	String tmp("lucy");
	
	if (name == "lucy") {
		cout << "name is right" << endl;
	}
	
	if (name == tmp) {
		cout << "name is right" << endl;
	}
	
	name.show();
    return 0;
}
